package com.leecode.exercise;

/**
 * @Author: shubin_yao
 * @Date: 2022/04/04/9:45
 * @Description:
 */
public class StringKh {

    public static void main(String[] args) {
        String s = "{[]()}";
        StringKh stringKh = new StringKh();
        boolean valid = stringKh.isValid(s);
        System.out.println(valid);
    }

    public boolean isValid(String s) {
        Stack_Array stack_array = new Stack_Array();
        for (int i = 0; i < s.length(); i++) {
            String c = String.valueOf(s.charAt(i));
            if (stack_array.isEmpty()) {
                stack_array.push(c);
                continue;
            }
            String top = (String) stack_array.peek();
            if (c.equals("{") && "}".equals(top)) {
                stack_array.pop();
                continue;
            }
            if (c.equals("(") && ")".equals(top)) {
                stack_array.pop();
                continue;
            }
            if (c.equals("[") && "]".equals(top)) {
                stack_array.pop();
                continue;
            }
            stack_array.push(c);
        }
        return stack_array.isEmpty();
    }
}
